﻿using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_right : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string usr = (string)Session["usr"];
        if (usr == null)
        {
            Response.Write("<script>alert('请返回到登录界面登录！!');window.open('login.aspx','_parent')</script>");
            Session.Clear();
        }
        else
        {

            Calendar1.Visible = false;
            this.Calendar1.SelectedDate = DateTime.Today;
            this.TextBox2.Text = this.Calendar1.SelectedDate.ToShortDateString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (content.Text == "")
        {
            Response.Write("<script>alert('提交内容不能为空!')</script>");
        }
        else if (TextBox1.Text == "")
        {
            Response.Write("<script>alert('文章题目不能为空!')</script>");
        }
        else if (DropDownList1.SelectedItem.Text.Trim() == "")
        {
            Response.Write("<script>alert('栏目不能为空!')</script>");
        }
        else if (TextBox6.Text == "")
        {
            Response.Write("<script>alert('发表姓名不能为空!')</script>");
        }
        else
        {
            string strConnection = "Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=|DataDirectory|\\web.mdb";
            OleDbConnection objConnection = new OleDbConnection(strConnection);
            objConnection.Open();
            string sqlStr = "insert into news(timu,time1,bumen,lanmu,name1,zw,cishu,shenhe) values ( '" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + DropDownList2.SelectedItem.Text.Trim() + "','" + DropDownList1.SelectedItem.Text.Trim() + "','" + TextBox6.Text.Trim() + "','" + content.Text.Trim() + "','" + TextBox4.Text.Trim() + "','等待审核')";
            OleDbCommand cmd = new OleDbCommand(sqlStr, objConnection);
            Response.Write("<script>alert('提交成功!')</script>");
            Response.AddHeader("Refresh", "0");  //刷新页面，并从新执行页面内容！
            cmd.ExecuteNonQuery();
            objConnection.Close();
            content.Text = "";
            TextBox1.Text = "";
            TextBox2.Text = "";
            DropDownList1.SelectedItem.Text = "";
            TextBox6.Text = "";
        }
      
    }

    protected void 时间响应_Click(object sender, EventArgs e)
    {
        Calendar1.Visible = true;
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        TextBox2.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
    }
}
